package com.hzit.controller.api;

import com.hzit.anno.RequiresPermissions;
import com.hzit.entity.Student;
import com.hzit.service.StudentService;
import com.hzit.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@RestController
@RequestMapping("/api/student")
@RefreshScope       // 如果不加改变配置不会立即生效
@Api(tags = "学生管理接口")
public class ApiStudentController {

	@Autowired
	private StudentService studentService;

	@Value("${student.name}")
	private String userName;
	@Value("${server.port}")
	private String port;

	//1. 查看所有学生列表
	@ApiOperation("学生列表")
	@GetMapping("/list")
	@RequiresPermissions(value = "student:list")
	public R list(){
		List<Student> list = studentService.list();
		return R.ok().data("port",port).data("list",list);
	}

	//2. 根据id查看学生列表
	@GetMapping("/findById/{sid}")
	@ApiOperation(value = "根据学生列表查询学生")
	public R findById(@PathVariable("sid")
					  @ApiParam(value = "学生学号",required = true)
			          Integer sid){
		Student student = studentService.getById(sid);
		return R.ok().data("port",port).data("student",student);
	}
}
